import 'package:flutter/material.dart';

class MyApp19 extends StatelessWidget {
  const MyApp19({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('GridView的基本使用'),
        backgroundColor: const Color.fromARGB(255, 232, 221, 10),
      ),
      // 固定个数
      body: GridView.extent(
        maxCrossAxisExtent: 100.0, // 设置侧轴方向子元素宽度，，此时每行展示的子元素个数是变化的
        mainAxisSpacing: 10.0,
        crossAxisSpacing: 5.0,
        childAspectRatio: 4 / 3,
        children: [
          Container(
            color: Colors.red,
            alignment: Alignment.center,
            child: const Text('传智播客1'),
          ),
          Container(
            color: Colors.orange,
            alignment: Alignment.center,
            child: const Text('传智播客2'),
          ),
          Container(
            color: Colors.yellow,
            alignment: Alignment.center,
            child: const Text('传智播客3'),
          ),
          Container(
            color: Colors.green,
            alignment: Alignment.center,
            child: const Text('传智播客4'),
          ),
          Container(
            color: Colors.cyan,
            alignment: Alignment.center,
            child: const Text('传智播客5'),
          ),
          Container(
            color: Colors.blue,
            alignment: Alignment.center,
            child: const Text('传智播客6'),
          ),
          Container(
            color: Colors.purple,
            alignment: Alignment.center,
            child: const Text('传智播客6'),
          ),
        ],
      ),
      // GridView.builder(
      //   gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
      //     crossAxisCount: 3,
      //     mainAxisSpacing: 5,
      //     crossAxisSpacing: 5,
      //   ),
      //   itemBuilder: (BuildContext context, int index) {
      //     return Container(color: Colors.blueAccent);
      //   },
      // ),
    );
  }
}
